/*
 * Copyright (c) $today.year-Now http://www.zxpnet.com All rights reserved.
 */

package com.zxp.springboot.controller;

import cn.hutool.http.useragent.UserAgent;
import cn.hutool.http.useragent.UserAgentUtil;
import com.google.common.collect.Maps;
import org.springframework.http.HttpHeaders;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;

/**
 * 测试请求参数示例
 *
 *
 * @author: shollin
 * @date: 2021/6/23/023 7:26
 */
@RestController
public class ParamController {

    @GetMapping("/car/{id}/aa/{username}")
    public HashMap<String,Object> getCar(@PathVariable("id") String id, @PathVariable("username") String name,
                                         @RequestHeader HttpHeaders headers,
                                         @RequestHeader(HttpHeaders.USER_AGENT) String userAgent
                                         //@CookieValue Cookie cookie
        ){

        HashMap<String,Object> map = Maps.newHashMap();
        map.put("id",id);
        map.put("name", name);
        map.put("header",headers);
//map.put("cookie", cookie);

        UserAgent ua = UserAgentUtil.parse(userAgent);

        ua.getBrowser().toString();//Chrome
        ua.getVersion();//14.0.835.163
        ua.getEngine().toString();//Webkit
        ua.getEngineVersion();//535.1
        ua.getOs().toString();//Windows 7
        ua.getPlatform().toString();//Windows


        return map;
    }
}
